package com.bilin.coin.list;

import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.CoinAssertBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.GsonUtil;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class CoinAssertList extends AbsPullToRefreshRecycleView<CoinAssertBean> {

    TextView tv_usable;

    public CoinAssertList(BaseAppCompatActivity activity, RecyclerView recyclerView, TextView tv_usable) {
        super(activity,recyclerView, false,false,false, false);
        this.tv_usable = tv_usable;
    }
    public CoinAssertList(BaseAppCompatActivity activity, RecyclerView recyclerView) {
        super(activity,recyclerView, false,false,false, false);
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        List<CoinAssertBean> productHomeBean = GsonUtil.jsonToList(dataJson, CoinAssertBean.class);
        totalCount = productHomeBean.size();
        fillKBAmount(productHomeBean);
        return productHomeBean;
    }

    private void fillKBAmount( List<CoinAssertBean> data) {
        for (CoinAssertBean coinAssertBean : data) {
            if (coinAssertBean.getCoinName().equals("矿币")) {
                tv_usable.setText(coinAssertBean.getUsable());
                return;
            }
        }
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage",page+"");
        params.put("pageSize",pageSize+"");
        return params;
    }

  /*  @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 15), 0x1999));
        return manager;
    }*/

    @Override
    public String fillUrl() {
        return "/api/wallet/list";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, CoinAssertBean item) {
        helper.setText(R.id.tv_name,item.getCoinName());
        helper.setText(R.id.tv_amount,item.getUsable());
        helper.setText(R.id.tv_amount_rmb,"¥ "+item.getCoinToRmb());
        helper.setText(R.id.tv_price,"≈"+item.getPrice()+" CNY");
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_coin_assert;
    }
}
